home *** CD-ROM | disk | FTP | other *** search
/ Asymetrix Multimedia Toolbook 4.0 (CBT Edition) / Asymetric Multimedia Toolbook 4.0 (CBT Edition).iso / ctb40mt.z / ADVANCED.ATS next >
Text File  |  1995-11-13  |  61KB  |  1,971 lines

  1. ACTION    "Open a file using Common Open Dialog"
  2. BEHAVIOR    "Opens a file that the user has chosen. "
  3. CATEGORY    Files
  4. HANDLERS    buttonClick, buttonUp, buttonDown, buttonDoubleClick, rightButtonDown, rightButtonUp, rightButtonDoubleClick
  5. ARG    caption    IS    "Open"
  6. ARG    prompt    IS    "Choose the file to open"
  7. ARG    extension    IS    "*.txt"
  8. ARG    Directory    IS    "."
  9. {
  10.     linkDll sysToolBookDirectory & "tb40dlg.dll"
  11.         string openDlg(string,string,string,string)
  12.     end    linkDLL
  13.     
  14.     get openDlg("$$Directory","$$extension","$$prompt","$$caption")
  15.     if it <> null    
  16.         clear sysError
  17.         openfile it
  18.         if sysError <> null
  19.             request "The file"&&it&&"could not be opened"
  20.         end if
  21.     end if
  22.     unlinkDLL sysToolBookDirectory & "tb40dlg.dll"
  23. }
  24.  
  25. SCRIPT    "Insert a textline"
  26. BEHAVIOR    "Use if you need to insert a single line and maintain the fields sorted order. "
  27. CATEGORY    Text
  28. {
  29. to get insertLine txt,newLine
  30.     if txt is null
  31.         return newLine
  32.     end
  33.     set start to 1  -- first textline
  34.     set tlc to textlinecount(txt)
  35.     set ending to tlc -- last textline
  36.     local insertSpot
  37.     while start <= ending 
  38.         set midPoint to (start+ending) div 2 
  39.         set middleLine to textline midPoint of txt
  40.         conditions
  41.             when newLine < middleLine as text
  42.                 -- start looking at values less than current midPoint
  43.                 set ending to midPoint-1
  44.                 set insertSpot to midPoint
  45.             when newLine > middleLine as text
  46.                 -- start looking at values greater than current midPoint
  47.                 set start to midPoint+1
  48.                 set insertSpot to midPoint+1
  49.             else
  50.                 -- the item already exists
  51.                 set insertSpot to midPoint
  52.                 break while
  53.         end
  54.     end
  55.     if insertSpot > tlc
  56.         put newLine before textline insertSpot of txt
  57.     else
  58.         put newLine&crlf before textline insertSpot of txt
  59.     end
  60.     return txt
  61. end
  62. }
  63.  
  64. SCRIPT    "Get the name of MRU file"
  65. BEHAVIOR    "A method for getting the name of any of the MRU (most recently used) files listed at the bottom of the author level file menu. "
  66. CATEGORY    Files
  67. {
  68. to handle loadFile mAlias      -- possible custom message
  69. -- Pass mAlias in from menuItemSelected. 
  70. -- See page 13-30 of the ToolBook User Manual for an example
  71.         linkDLL sysToolBookDirectory & "tb40WIN.DLL"
  72.             STRING     getIniVar(STRING,STRING,STRING)
  73.                            -- section, item, file
  74.         end linkDLL
  75.         
  76.         get getIniVar("files", mAlias, "toolbook.ini") 
  77.         request it
  78. --        go to page 1 of book it    -- same as default behavior
  79.         unlinkDLL sysToolBookDirectory & "tb40WIN.DLL"
  80. end loadFile
  81. }
  82.  
  83. ACTION    "Show or hide object(s) with transition"
  84. BEHAVIOR    "Allows user to $$show an object with a transition effect "
  85. CATEGORY    Effects
  86. ARG    speed    ONEOF    "slow,normal,fast"    IS    "normal"
  87. ARG    effect    ONEOF    "blinds,dissolve,drip,fade,iris,push,puzzle,rain,slide,spiral,split,tear,turnPage,wipe,zoom"    IS    "fade"
  88. ARG    myObjects    IS    "objects of this page"    help    "Set to a reference ($$myObjects) to an object or objects."
  89. ARG    show    ONEOF    "show,hide"    IS    "show"    help    "Show hidden objects or hide shown objects."
  90. {
  91. -- This script works fine as is, but there are so many  
  92. -- variations, consider doing a little experimentation.
  93.       set sysSuspendMessages to TRUE
  94.     linkDLL "USER"
  95.         int LockWindowUpdate(WORD)
  96.     end    linkDLL
  97.     set pObjList to $$myObjects
  98.     if pObjList is Null and object of self is not in "page,background,book"
  99.         set pObjList to self
  100.     end if
  101.     set sysLockScreen to true
  102.     while (pObjList is not NULL)
  103.         pop pObjList
  104.         $$show it
  105.     end
  106.  
  107.  -- Reset sysLockScreen, get rid of Windows' Paint message:
  108.      get LockWindowUpdate(sysClientHandle)
  109.     sysLockScreen = false
  110.     get lockWindowUpdate(0)
  111.  
  112.     transition "$$effect $$speed" to this page
  113.     unlinkDLL "USER"
  114. }
  115.  
  116. SCRIPT    "Convert textlines to a list"
  117. BEHAVIOR    "This handler converts a string delimited by CRLF's to a list delimited by commas. "
  118. CATEGORY    Text
  119. {
  120. to get textLinesToList txt
  121.     local STACK lst
  122.     step i from textlinecount(txt) to 1 by - 1
  123.         push textline i of txt onto lst
  124.     end
  125.     return lst
  126. end textLinesToList
  127. }
  128.  
  129. SCRIPT    "Display 1-D array values"
  130. BEHAVIOR    "Displays the contents of a one-dimensional array. "
  131. CATEGORY    Data
  132. {
  133. to handle request1DArray x[]
  134.     local retval
  135.     set d to dimensions(x)
  136.     step i from 1 to d
  137.         put x[i] after retval
  138.         if i < d
  139.             put crlf after retval
  140.         end    if
  141.     end    step
  142.     request retval
  143. end    request1DArray
  144. }
  145.  
  146. SCRIPT    "Display 2-D array values"
  147. BEHAVIOR    "Displays the contents of a two-dimensional array. "
  148. CATEGORY    Data
  149. {
  150.   to handle request2DArray x[][]
  151.     local retval
  152.     set d to dimensions(x)
  153.     step i from 1 to item 1 of d
  154.         step j from 1 to item 2 of d
  155.             put x[i][j] after retval
  156.             if j < item 2 of d
  157.                 put tab after retval
  158.             end    if
  159.         end    step
  160.         if i < item 1 of d
  161.             put crlf after retval
  162.         end    if
  163.     end    step
  164.     request retval
  165.  end request2DArray
  166. }
  167.  
  168. SCRIPT    "Sorting a 1-D array"
  169. BEHAVIOR    "This is an OpenScript implementation of the standard recursive quick sort. "
  170. CATEGORY    Data
  171. {
  172. -- The next three handlers make up a  
  173. -- standard recursive QuickSort.
  174. to handle quicksort fArray[] by reference
  175.     system s_noSwap
  176.     set s_noSwap to 0
  177.     send quicksrt fArray, 1, dimensions ( fArray )
  178. end    quicksort
  179.  
  180. to handle quicksrt fArray[] by reference, lo, hi
  181.     system  s_noSwap
  182.     if hi > lo 
  183.         send swap  fArray, lo, ((lo+hi) div 2)
  184.         set lst to lo
  185.         step i from (lo+1) to hi
  186.             if fArray[i] < fArray[lo] as text
  187.                 increment lst
  188.                 send swap fArray, lst, i
  189.             else
  190.                 increment s_noswap
  191.             end
  192.         end 
  193.         send swap fArray,lo,lst 
  194.            send quicksrt fArray, lo, lst-1
  195.         send quicksrt fArray, lst+1,hi
  196.        end
  197. end    quicksrt
  198.  
  199. to handle swap fArray[] by reference, x, y
  200.     local temp
  201.     set temp to fArray[x]
  202.     set fArray[x] to fArray[y]
  203.     set fArray[y] to temp
  204. end    swap
  205. }
  206.  
  207. SCRIPT    "Sorting a 2-D array"
  208. BEHAVIOR    "This is an OpenScript implementation of the standard recursive quick sort adjusted for two dimensions. "
  209. CATEGORY    Data
  210. {
  211. -- keep in mind that arrays are passed by reference, not by value
  212. --
  213. to handle twoDquicksort fArray[][] by reference,sortColumn,dtype
  214.     system stbk_noSwap
  215.  
  216.     set stbk_noSwap to 0
  217.     send twoDquicksrt fArray, 1, item 1 of dimensions(fArray),sortColumn,dtype
  218. end
  219.  
  220. to handle twoDquicksrt fArray[][] by reference, lo, hi,sortColumn,dtype
  221.     system  stbk_noSwap
  222.     if hi > lo 
  223.         send swap  fArray, lo, ((lo+hi) div 2)
  224.         set lst to lo
  225.         step i from (lo+1) to hi
  226.             conditions
  227.                 when dtype is "text"
  228.                     set test to fArray[i][sortColumn] < fArray[lo][sortColumn] as text
  229.                 when dtype is "date"
  230.                     set test to fArray[i][sortColumn] < fArray[lo][sortColumn] as date
  231.                 else
  232.                     set test to fArray[i][sortColumn] < fArray[lo][sortColumn] as number
  233.             end
  234.             if test
  235.                 increment lst
  236.                 send swap fArray, lst, i
  237.             else
  238.                 increment stbk_noswap
  239.             end if
  240.         end step
  241.         send swap fArray,lo,lst 
  242.            
  243.            send twoDquicksrt fArray, lo, lst-1,sortColumn,dtype
  244.         send twoDquicksrt fArray, lst+1,hi,sortColumn,dtype
  245.        end
  246. end
  247.  
  248. to handle swap fArray[][] by reference, a, b
  249.     local temp
  250.     step i from 1 to item 2 of dimensions (fArray)
  251.         set temp to farray[a][i]
  252.         set farray[a][i] to farray[b][i]
  253.         set farray[b][i] to temp
  254.     end
  255. end
  256. }
  257.  
  258. SCRIPT    "Using a RECT structure"
  259. BEHAVIOR    "The following functions are useful for dealing with windows functions that require or return a RECT structure. "
  260. CATEGORY    Data
  261. {
  262. -- lst is a list of 4 integers
  263. -- pRect is a locked pointer to 8 bytes
  264. to handle setRect lst,pRect
  265.     step i from 0 to 6 by 2
  266.         pop lst
  267.         get pointerInt(i,pRect,it)
  268.     end
  269. end
  270.  
  271. -- pRect is a locked pointer to 8 bytes
  272. to get getRect pRect
  273.     local retval
  274.     step i from 6 to 0 by -2
  275.         push pointerInt(i,pRect) onto retval
  276.     end
  277.     return retval
  278. end
  279. }
  280.  
  281. SCRIPT    "Using Windows pointers"
  282. BEHAVIOR    "The following functions are helpful if you need to allocate a pointer for calling a Windows function. "
  283. CATEGORY    Windows
  284. {
  285. -- the link statements for needed functions below
  286. to handle linkMemFunctions
  287.     linkDLL "KERNEL"
  288.         WORD     GlobalAlloc(WORD,DWORD)
  289.         WORD     GlobalFree(WORD)
  290.         WORD     GlobalHandle(WORD)
  291.         POINTER GlobalLock(WORD)    
  292.         WORD     GlobalUnlock(WORD)
  293.     end linkDLL
  294. end    linkMemFunctions
  295.  
  296. to get getWinPointer nSize
  297.     local word hMem
  298.     local retValue
  299.     hMem = GlobalAlloc(66,nSize)
  300.     return GlobalLock(hMem)
  301. end getWinPointer
  302.  
  303. to get freeWinPointer pMem
  304.     local word hMem, retValue
  305.     hMem = GlobalHandle(item 1 of pMem)
  306.     retValue = GlobalUnlock(hMem)
  307.     return GlobalFree(hMem)
  308. end    freeWinPointer
  309. }
  310.  
  311. ACTION    "Create shuffled array"
  312. BEHAVIOR    "Creates an array with the elements 1 to $$num (num) in a random order. "
  313. CATEGORY    Data
  314. ARG    num    IS    "52"    help    "Enter the number of elements to be shuffled."
  315. {
  316.     local INT result[$$num]
  317.     local LOGICAL table[$$num]
  318.  
  319.     set i to 1
  320.     while i <= $$num
  321.         set x to random($$num)
  322.         if table[x] is not true
  323.             set table[x] to true
  324.             set result[i] to x
  325.             increment i
  326.         end    if
  327.     end while
  328. }
  329.  
  330. ACTION    "Find text in a list box"
  331. BEHAVIOR    "Searches a list box (single or multi-select) for some text and selects the line that the text is on. "
  332. CATEGORY    Text
  333. ARG    searchText    IS    "What are you looking for?"    help    "Place your text here or modify the script accordingly."
  334. ARG    fieldName    IS    "searchField"    help    "Set this to the name of the list box you want to search."
  335. {
  336.     set searchtext to "$$searchText"
  337. --     or try
  338. --     ask "What text would you like to search for?" with \
  339. --    "$$searchText"
  340. --     if it is null or it is "Cancel"
  341. --        break
  342. --    else
  343. --         set searchText to it
  344. --    end if        
  345.     set sysLockScreen to TRUE
  346.     set oldFT to fieldType of field "$$fieldName"
  347.     set fieldType of field "$$fieldName" to wordWrap
  348.     search for searchText
  349.     get item 3 of selectedTextState
  350.     set fieldType of field "$$fieldName" to oldFT
  351.      if it <> NULL
  352.         set selectedTextLines of field "$$fieldName" to it 
  353.         set scroll of field "$$fieldName" to it - 1 
  354.     else
  355.         request QUOTE & searchText & QUOTE && "was not found."
  356.     end if
  357. }
  358.  
  359. SCRIPT    "Limit the length of an entry"
  360. BEHAVIOR    "When a key is pressed, this handler checks that the charCount of the text of the field is within the limits specified in the script. "
  361. CATEGORY    Data
  362. {
  363. -- does not allow entry of more than specified
  364. -- amount of characters. Place this hander in a field.
  365. to handle keyChar keyPressed
  366.     local INT maxCharAllowed
  367.     local INT currentCount
  368.     maxCharAllowed = 10
  369.     currentCount = charCount(my text)
  370.     if (currentCount >= maxCharAllowed) \
  371.      or (keyPressed = keyEnter and currentCount >= \
  372.      maxCharAllowed - 1)
  373.         beep 1
  374.     else
  375.         forward
  376.     end    if
  377. end    keyChar
  378. }
  379.  
  380. SCRIPT    "Enable overwrite in a field"
  381. BEHAVIOR    "Allows a field to toggle between Insert and Overwrite mode common to many word processors. "
  382. CATEGORY    Text
  383. {
  384. to handle keyDown key
  385.     system LOGICAL overWriteFlag
  386.     if key is keyInsert
  387.         set overWriteFlag to not overWriteFlag 
  388.     end if
  389.     forward
  390. end    keyDown
  391.  
  392. to handle keyChar key
  393.     system LOGICAL overWriteFlag
  394.     set sysLockScreen to true
  395.  
  396.     if overWriteFlag and (key <> keyBack)
  397.         send clear
  398.     end if
  399.     forward
  400. end    keyChar
  401. }
  402.  
  403. ACTION    "Sum the lines in a text field"
  404. BEHAVIOR    "This script adds the numbers on each line in the text field $$numbers and puts the result in the text field $$total. "
  405. CATEGORY    Math
  406. ARG    numbers    IS    "numbers"    help    "The name of the field that has the numbers in it."
  407. ARG    total    IS    "total"    help    "The name of the field that will have the total in it."
  408. {
  409.     set total to 0
  410.     step i from 1 to textLineCount(text of field "$$numbers")
  411.         set temp to (textline i of text of field "$$numbers")
  412.         set total to total + temp
  413.     end
  414.     put total into text of field "$$total"  
  415. }
  416.  
  417. SCRIPT    "Get the sine from points"
  418. BEHAVIOR    "Get the sine of an angle as described by two points and the default coordinate system. "
  419. CATEGORY    Math
  420. {
  421. to get sinFromPoints x1,x2,y1,y2
  422.     x = abs(x2 - x1)
  423.     y = abs(y2 - y1)
  424.     conditions
  425.     when x = 0
  426.         r = 1 
  427.     when y = 0
  428.         r = 0
  429.     else
  430.     -- this is where your high school algebra comes back to you
  431.         r = y/sqrt(x^2 + y^2)
  432.     end conditions
  433.     if y2 < y1
  434.         r = -r
  435.     end if
  436.     return r
  437. end sinFromPoints
  438. }
  439.  
  440. SCRIPT    "Get the cosine from points"
  441. BEHAVIOR    "Get the cosine of an angle as described by two points and the default coordinate system. "
  442. CATEGORY    Math
  443. {
  444. to get cosFromPoints x1,x2,y1,y2
  445.     x = abs(x2 - x1)
  446.     y = abs(y2 - y1)
  447.     conditions
  448.     when x = 0
  449.         r = 0 
  450.     when y = 0
  451.         r = 1
  452.     else
  453.     -- this is where your high school algebra comes back to you
  454.         r = x/sqrt(x^2 + y^2)
  455.     end conditions
  456.     if x2 < x1
  457.         r = -r
  458.     end if
  459.     return r
  460. end cosFromPoints
  461. }
  462.  
  463. SCRIPT    "Get the angle between points"
  464. BEHAVIOR    "Returns the angle between a point on a vector (like an animation) and another point (like a mouse click). "
  465. CATEGORY    Math
  466. {
  467. to get myAngle loc, obj, vector 
  468.     -- loc is (possibly) where the mouse was clicked
  469.     -- obj is an object reference to something (moving?) on a
  470.     -- vector, which is really a direction defined by a point, so it's a point
  471.     -- like this:
  472.     
  473.     -- . vector
  474.     --  \      . loc
  475.      --   \    /    
  476.     --    \  /
  477.     --       . obj
  478.     
  479.     -- what's the angle?
  480.     -- returns angle in radians
  481.  
  482.     system s_2PI,s_PIdiv2 
  483.     -- only calculate these once
  484.     if s_2PI is null 
  485.         set s_2PI to 2 * PI
  486.     end if 
  487.  
  488.     if s_PIdiv2 is null 
  489.         set s_PIdiv2 to PI/2 
  490.     end if
  491.      
  492.     -- see "Get the center of an object"
  493.     set yCenter to objectCenter (obj) 
  494.     pop yCenter into xCenter     
  495.     set yOffset to loc 
  496.     pop yOffset into xOffset
  497.     -- You may want these next two as system variables, because
  498.     -- they're no likely to change. 
  499.     set yVec to vector
  500.     pop yVec into xVec 
  501.     --     see "Get the cosine from points" and "Get the sine from points"
  502.     set mouseSin to (sinFromPoints(xCenter,yCenter,xOffset,yOffset)) 
  503.     set mouseCos to (cosFromPoints(xCenter,yCenter,xOffset,yOffset))
  504.     set vecSin to (sinFromPoints(xCenter,yCenter,xVec,yVec)) 
  505.     set vecCos to (cosFromPoints(xCenter,yCenter,xVec,yVec))
  506.     
  507. --    angle between them is: arctan(x2/y2) - arctan(x1/y1)
  508.     set myAngle to ((aTan2(vecCos,vecSin)) - (aTan2(mouseCos,mouseSin)) + s_PIdiv2) -- adjust quadrant
  509.  
  510.  -- determine the quadrant        
  511.     if myAngle > PI
  512.         if myAngle > s_2PI
  513.             set myAngle to myAngle mod s_2PI
  514.         else
  515.             set myAngle to (myAngle mod PI) - PI
  516.         end if
  517.     end if
  518.     return myAngle
  519. end myAngle
  520. }
  521.  
  522. SCRIPT    "Search and replace text"
  523. BEHAVIOR    "This function searches 'txt' for all occurrences of 'searchString' and replaces it with 'replaceString'. "
  524. CATEGORY    Utilities
  525. {
  526. -- this function searches txt for all occurrences of searchString 
  527. -- and replaces it with replaceString.
  528. -- If asWord is true, replaceString replaces searchString only where 
  529. -- searchString appears as a word.
  530. -- (A word is defined as a string that is preceded and followed by
  531. -- either the beginning or end of txt, or by any character in the 
  532. -- wordDelimit string.  The wordDelimit string contains 
  533. -- space, tab, crlf, and common punctuation and mathematical operators.)
  534.  
  535. to get searchReplace txt,searchFor,replaceWith,asWord
  536.     if asWord is null
  537.         set asWord to "false"
  538.     end if
  539.     runningTotal = 1
  540.     totalChars=charcount(txt)
  541.     searchLen=charcount(searchFor)
  542.     replaceLen=charcount(replaceWith)
  543.     -- this string contains all characters that are legally adjacent
  544.     -- to a word.
  545.     wordDelimit = " " & tab & crlf & "-+*/<>,()[];^=&.?':" & quote 
  546.     while runningTotal <= totalChars
  547.         set curTxt to chars runningTotal to totalChars of txt
  548.         curOffset = offset(searchFor,curTxt)
  549.         if curOffset = 0
  550.             break while
  551.         else
  552.             startPos = (runningTotal+curOffset-1)
  553.             endPos = (runningTotal+curOffset+searchLen-2)
  554.             if asWord is true
  555.                 -- test if this occurance is an isolated word:
  556.                 if not ((startPos = 1 or char (startPos - 1) \
  557.                  of txt is in wordDelimit) and\
  558.                  (endPos = totalChars or char endPos + 1 \
  559.                  of txt is in wordDelimit))
  560.                      increment runningTotal by curOffset+searchLen-1
  561.                     continue while
  562.                 end if
  563.             end    if
  564.             set chars startPos to endPos of txt to replaceWith
  565.             increment runningTotal by curOffset+replaceLen-1
  566.             increment totalChars by replaceLen - searchLen
  567.         end    if    
  568.     end    while
  569.     return txt
  570. end    searchReplace
  571. }
  572.  
  573. SCRIPT    "Change the behavior of the Back command"
  574. BEHAVIOR    "Provides an alternative to the standard behavior of ToolBook's 'Back' command "
  575. CATEGORY    Navigation
  576. {
  577. to handle enterApplication
  578.     system s_backMessageSent
  579.     -- initialize system variable
  580.     s_backMessageSent = false
  581.     -- turn off syshistory
  582.     syshistoryrecord = false
  583.     clear syshistory
  584.     forward
  585. end enterApplication
  586.  
  587. to handle leavePage
  588.     system s_backMessageSent
  589.     -- only puts page on syshistory if navigation is *not* initiated by BACK
  590.     if targetWindow is mainWindow
  591.         if s_backMessageSent is false
  592.             push this page onto syshistory
  593.         else
  594.             s_backMessageSent = false
  595.         end
  596.     end if
  597.     forward
  598. end leavePage
  599.  
  600. to handle back
  601.     system s_backMessageSent
  602.     if itemcount(syshistory) > 0
  603.         s_backMessageSent = true
  604.         pop syshistory
  605.         in mainwindow
  606.             go to it
  607.         end in
  608.     else
  609.         request "You are already all the way back."
  610.     end if
  611. end back
  612. }
  613.  
  614. SCRIPT    "Multi-select field becomes extend-select"
  615. BEHAVIOR    "This script will make a multi-select field much more versatile, acting like a single-select, multi-select or extend-select "
  616. CATEGORY    Utilities
  617. {
  618. to handle buttonDown loc,isShift,isControl
  619.     -- Script in field to be ExtendSelect
  620.     -- Click without shift, then click with shift for extended selection
  621.     -- Hold ctrl for normal multi-select
  622.     -- Without shift or control for normal single-select
  623.     system WORD s_shiftStart
  624.      -- fieldType must be multiSelect for this to work
  625.     if fieldType of self <> "multiSelect"
  626.         fieldType of self = multiSelect
  627.     end if
  628.      sysLockScreen = TRUE
  629.     conditions
  630.     when isShift
  631.         if s_shiftStart is not null
  632.             shiftEnd = item 1 of textFromPoint(loc)
  633.             if shiftEnd < s_shiftStart
  634.                 counter = -1
  635.             else
  636.                 counter = 1
  637.             end if
  638.             clear my selectedTextlines
  639.             step i from s_shiftStart to shiftEnd by counter
  640.                 push i onto my selectedTextlines
  641.             end step
  642.         end if
  643.         break buttonDown
  644.     when not isControl
  645.         clear my selectedTextlines
  646.         my selectedTextlines = item 1 of textFromPoint(loc)
  647.         sysLockScreen = FALSE
  648.     end conditions
  649.     s_shiftStart = item 1 of textFromPoint(loc)
  650.     forward
  651. end buttonDown
  652. }
  653.  
  654. SCRIPT    "Drag objects"
  655. BEHAVIOR    "Easy way to drag objects around at reader level. "
  656. CATEGORY    Utilities
  657. {
  658. to handle buttonDown loc
  659.     local STACK bnds,mouseOffset
  660.     linkDLL "user"
  661.         int getsystemmetrics(int)
  662.     end    linkDLL
  663.  
  664.     -- check if the user has swapped mouse buttons.
  665.     if getsystemmetrics(23) >0
  666.         set leftMouseButton to keyRightButton
  667.     else
  668.         set leftMouseButton to keyLeftButton
  669.     end    if
  670.  
  671.     unlinkDLL "user"
  672.     set bnds to bounds of target
  673.     set mouseOffset to item 1 of loc - item 1 of bnds,\
  674.       item 2 of loc - item 2 of bnds
  675.     
  676.     while keystate(leftMouseButton)is down
  677.         newloc = sysMousePosition
  678.         if newLoc <> loc
  679.             set position of target to \
  680.               item 1 of newLoc-item 1 of mouseOffset,\
  681.               item 2 of newLoc-item 2 of mouseOffset
  682.             set loc to newLoc
  683.         end    if
  684.     end while
  685. end    buttonDown
  686. }
  687.  
  688. SCRIPT    "Draw a selection rectangle"
  689. BEHAVIOR    "Draws a selection rectangle (rubber band) for selecting and clearing objects at reader level. "
  690. CATEGORY    Draw
  691. {
  692. to handle buttonDown loc
  693.     system xy
  694.     set myObj to objectFromPoint (loc)
  695.     if myObj = NULL or object of parent of myObj = background
  696.         draw rectangle from loc to loc
  697.         set name of selection to "selectionRectangle"
  698.         set transparent of selection to TRUE
  699.         set lineStyle of selection to dotted
  700.         set xy to position of selection
  701.     end if
  702.     
  703. end buttonDown
  704.  
  705.  
  706. to handle buttonStillDown    
  707.     send drawSelectionRectangle        
  708. end buttonStillDown
  709.  
  710. to handle buttonUp
  711.     if selectionRectangleDrawn of this page <> TRUE
  712.         break
  713.     end if
  714.     set x to item 1 of bounds of selection
  715.     set y to item 2 of bounds of selection
  716.     set cx to item 3 of bounds of selection
  717.     set cy to item 4 of bounds of selection
  718.     step i from 1 to itemCount (objects of this page)
  719.         if x < item 1 of bounds of item i of objects of this page and \
  720.             y < item 2 of bounds of item i of objects of this page and \
  721.             cx > item 3 of bounds of item i of objects of this page and \
  722.             cy > item 4 of bounds of item i of objects of this page
  723.             
  724.             extend select item i of objects of this page
  725.         end if            
  726.     end step
  727.     if itemCount (selection) >= 2 -- 1 = selectionRectangle
  728.         -- modify this clause for different behavior
  729.         request "Delete all enclosed objects?" with "Yes" or "No"
  730.         if it = "Yes"
  731.             send clear
  732.         else
  733.             set selection to rectangle "selectionRectangle"
  734.             send clear
  735.         end if
  736.     else
  737.         set selection to rectangle "selectionRectangle"
  738.         send clear
  739.     end if
  740. end buttonUp
  741.     
  742. to handle drawSelectionRectangle
  743.     system xy
  744.     set selectionRectangleDrawn of this page to TRUE    
  745.     if item 1 of sysMousePosition < item 1 of xy and \
  746.         item 2 of sysMousePosition > item 2 of xy            
  747.         set thirdQuadrant to TRUE
  748.     else
  749.         set thirdQuadrant to FALSE
  750.     end if
  751.         
  752.     if item 1 of sysMousePosition > item 1 of xy and \
  753.         item 2 of sysMousePosition < item 2 of xy            
  754.         set firstQuadrant to TRUE
  755.     else
  756.         set firstQuadrant to FALSE
  757.     end if
  758.                 
  759.     conditions        
  760.       when not thirdQuadrant and not firstQuadrant    
  761.           set temp to xy
  762.          set item 3 of temp to item 1 of sysMousePosition
  763.          set item 4 of temp to item 2 of sysMousePosition
  764.             
  765.       when thirdQuadrant and not firstQuadrant
  766.           set temp to sysMousePosition
  767.           set item 2 of temp to item 2 of xy
  768.           set item 3 of temp to item 1 of xy
  769.           set item 4 of temp to item 2 of sysMousePosition
  770.                 
  771.      when not thirdQuadrant and firstQuadrant
  772.          set temp to sysMousePosition
  773.          set item 1 of temp to item 1 of xy
  774.          set item 3 of temp to item 1 of sysMousePosition
  775.          set item 4 of temp to item 2 of xy
  776.                 
  777.     end conditions        
  778.     set bounds of selection to temp                
  779. end drawSelectionRectangle  
  780. }
  781.  
  782. SCRIPT    "Resize a polypoint object"
  783. BEHAVIOR    "This handler will proportionally size any polygon, irregularPolygon, line, angledLine, or curve. "
  784. CATEGORY    Draw
  785. {
  786. -- Proportionally resizes current object by percentage:
  787. -- Example: to make a polygon 90% of its original size, 
  788. -- you'd call this function like this:
  789. -- send resize polygon "foo",.9
  790.  
  791. to handle resize curObj,amount
  792.     set b to bounds of curobj
  793.     -- get center of object
  794.     set cx to item 1 of b + (item 3 of b - item 1 of b) /2
  795.     set cy to item 2 of b + (item 4 of b - item 2 of b) /2
  796.     -- make sure object has settable vertices
  797.     set curObjType to object of curObj
  798.     if curObjType is not in \
  799.      "polygon,irregularPolygon,line,angledLine,curve"
  800.         break
  801.     end    if
  802.     set v to vertices of curObj
  803.     -- walk through vertices, convert to polar, resize each vector,
  804.     -- convert back
  805.     step i from 1 to itemCount(v) by 2
  806.         set x to item i of v
  807.         set y to item i+1 of v
  808.         -- x,y distance of each point from center
  809.         set dx to x-cx
  810.         set dy to y-cy
  811.         -- find length and angle of vector:
  812.         -- atan2 is undefined at x=0,y=0:
  813.         if dx=0 and dy=0
  814.             set radians to 0
  815.             set h to 0
  816.         else
  817.             -- resize occurs here
  818.             set h to hypotenuse(dx,dy)*amount
  819.             set radians to atan2(dy,dx)
  820.         end    if
  821.         set item i of v to cx+cos(radians)*h
  822.         set item i+1 of v to cy+sin(radians)*h
  823.     end    step
  824.     set vertices of curObj to v
  825. end resize
  826. }
  827.  
  828. SCRIPT    "Search and replace in all a book's scripts"
  829. BEHAVIOR    "Searches through all the scripts of a book for a string and replaces it. "
  830. CATEGORY    Debug
  831. {
  832. to handle SearchNReplace
  833.     set sysTimeFormat to "seconds"
  834.     local szBackgroundName
  835.     clear sysError
  836.     ask "Enter text to be replaced:"
  837.     if sysError <> "cancel" and it is not null
  838.         set textToReplace to it
  839.     else
  840.         break buttonUp
  841.     end    if
  842.     ask "Enter text to replace" && textToReplace && "with:"
  843.     if sysError <> "cancel" and it is not null
  844.         set replaceText to it
  845.     else
  846.         break buttonUp
  847.     end    if
  848.     set startTime to sysTime
  849.     set sysCursor to 4
  850.     if script of this book contains textToReplace
  851.         step i from 1 to wordCount(script of this book)
  852.             if word i of script of this book = textToReplace as text
  853.                 put replaceText into word i of script of this book
  854.             end    if
  855.         end    step
  856.     end    if
  857.     step n from 1 to pageCount of this book
  858.         go to page n
  859.         step i from 1 to itemCount(objects of this page)
  860.             if script of item i of objects of this page contains textToReplace
  861.                 step j from 1 to wordCount(script of item i of objects of this page)
  862.                     if word j of script of item i of objects of this page = textToReplace as text
  863.                         put replaceText into word j of script of item i of objects of this page
  864.                     end    if
  865.                 end    step
  866.             end if
  867.             if object of item i of objects of this page is group
  868.                 get groupReplace(item i of objects of this page, \
  869.                         textToReplace,replaceText)
  870.             end    if
  871.         end    step
  872.         if uniqueName of this background <> szBackgroundName as text
  873.             set szBackgroundName to uniqueName of this background
  874.             step i from 1 to itemCount(objects of this background)
  875.                 if script of item i of objects of this background contains textToReplace
  876.                     step j from 1 to wordCount(script of item i of objects of this background)
  877.                         if word j of script of item i of objects of this background = textToReplace as text
  878.                             put replaceText into word j of script of item i of objects of this background
  879.                         end    if
  880.                     end    step
  881.                 end if 
  882.                 if object of item i of objects of this background is group
  883.                     get groupReplace(item i of objects of this background, \
  884.                             textToReplace,replaceText)
  885.                 end    if
  886.             end
  887.             if script of this background contains textToReplace
  888.                 step i from 1 to wordCount(script of this background)
  889.                     if word i of script of this background = textToReplace as text
  890.                         put replaceText into word i of script of this background
  891.                     end    if
  892.                 end    step
  893.             end    if
  894.         end    if
  895.         if script of this page contains textToReplace
  896.             step i from 1 to wordCount(script of this page)
  897.                 if word i of script of this page = textToReplace as text
  898.                     put replaceText into word i of script of this page
  899.                 end    if
  900.             end    step
  901.         end    if
  902.     end    step
  903.     request "Elapsed: " && sysTime - startTime && "seconds."
  904.     set sysCursor to default
  905. end    SearchNReplace
  906.  
  907. to get groupReplace groupID,textToReplace,replaceText
  908.     step i from 1 to itemCount(objects of groupID)
  909.         if script of item i of objects of groupID contains textToReplace
  910.             step n from 1 to wordCount(script of item i of objects of groupID)
  911.                 if word n of script of item i of objects of groupID = textToReplace as text
  912.                     put replaceText into word n of script of item i of objects \
  913.                             of groupID
  914.                 end    if
  915.             end    step
  916.         end    if
  917.         if object of item i of objects of groupID is group
  918.             get groupReplace(item i of objects of groupID,textToReplace, \
  919.                     replaceText)
  920.         end    if
  921.     end    step
  922.     return true
  923. end    groupReplace
  924. }
  925.  
  926.  
  927. SCRIPT    "Unpack a DWord to three bytes"
  928. BEHAVIOR    "Takes a DWord and unpacks it into three bytes. Useful for getting colors and MIDI messages from Windows. "
  929. CATEGORY    Utilities
  930. {
  931. to get explicitByte packedDWord    
  932.     r = (packeddword mod 256)
  933.     g = (packeddword mod 65536) bitShiftRight 8
  934.     b = packeddword bitShiftRight 16
  935.     push b onto it
  936.     push g onto it
  937.     push r onto it
  938.     return it
  939. end    explicitByte
  940. }
  941.  
  942. SCRIPT    "Pack three bytes into a DWord"
  943. BEHAVIOR    "Takes three bytes and packs them into a DWord. Useful for sending colors and MIDI messages to Windows. "
  944. CATEGORY    Utilities
  945. {
  946. to get packDWord rgb
  947.     set r to item 1 of rgb
  948.     set g to item 2 of rgb
  949.     set b to item 3 of rgb
  950.     set it to r + (g bitShiftLeft 8) + (b bitshiftLeft 16)
  951.     return it
  952. end    packDWord
  953. }
  954.  
  955. ACTION    "Create a link to timeGetTime()"
  956. BEHAVIOR    "Create a link to timeGetTime() for timing events. This is a better timer than getTickCount. "
  957. CATEGORY    Windows
  958. {
  959.     linkdll "mmSystem"
  960.         DWORD timeGetTime()
  961.     end
  962. }
  963.  
  964. ACTION    "Flash screen"
  965. BEHAVIOR    "Causes the ToolBook window to flash $$times times at a rate of approx. $$speed flashes per second. "
  966. CATEGORY    Effects
  967. ARG    times    IS    "5"    help    "Can be any number of times."
  968. ARG    speed    ONEOF    "1000,500,100"    IS    "100"    help    "the faster it flashes."
  969. {
  970. --to handle flash  -- suggested custom message
  971.     linkDLL "kernel"
  972.           word     globalAlloc(word,dword)
  973.         pointer globalLock(word)
  974.         word     globalUnlock(word)
  975.         word     globalFree(word)
  976.     end    linkDLL
  977.    
  978.    linkDLL "user"
  979.         word     invertRect(word,pointer)
  980.         word     getClientRect(word,pointer)
  981.         word     getDC(word)
  982.         int     releaseDC(word,word)
  983.     end    linkDLL
  984.     
  985.     set vHmem to globalAlloc(66, 8)
  986.     set vPtrMem to globalLock(vHmem)
  987.     get getClientRect(sysClientHandle,vPtrMem)
  988.     set vHDC to getDC(sysClientHandle)
  989.     set newSpeed to 1000/$$speed
  990.  
  991.     step i from 1 to $$times
  992.         get invertRect(vHDC,vPtrMem)
  993.         pause newSpeed ticks         
  994.         get invertRect(vHDC,vPtrMem)
  995.         pause newSpeed ticks
  996.     end step
  997.     
  998.     get releaseDC (sysClientHandle,vHDC)
  999.     get GlobalUnlock(vHmem)
  1000.     get GlobalFree(vHmem)
  1001.     unlinkDLL "kernel"
  1002.     unlinkDLL "user"
  1003. --end
  1004. }
  1005.  
  1006. SCRIPT    "Find the execution time"
  1007. BEHAVIOR    "Use these two handlers to make timing tests. They will automatically compare two tests run in a row. "
  1008. CATEGORY    Debug
  1009. {
  1010. to handle startTime
  1011.     system s_testTime
  1012.     linkDLL "mmSystem"
  1013.         DWORD timeGetTime()
  1014.     end    linkDLL
  1015.     set s_testTime to timeGetTime()
  1016. end    startTime
  1017.  
  1018. to handle showElapsedTime
  1019.     system s_testTime, s_lastTestTime
  1020.     
  1021.     set thisTestTime to (timeGetTime() - s_testTime) / 1000
  1022.     format number thisTestTime as "#.0"
  1023.     
  1024.     set prompt to "This test took" && thisTestTime && "seconds."
  1025.     if s_lastTestTime <> 0 and s_lastTestTime is not null
  1026.         get (thisTestTime - s_lastTestTime)
  1027.         set deltaTime to (it / min(s_lastTestTime,thisTestTime)) * 100
  1028.         format number deltaTime as "#.0"
  1029.         if deltaTime <> 0
  1030.             
  1031.             conditions
  1032.             when deltaTime < 0
  1033.                 set relation to "faster"
  1034.             when deltaTime > 0
  1035.                 set relation to "slower"
  1036.             end    conditions
  1037.  
  1038.             get abs(deltaTime)
  1039.             format number it as "#.0"
  1040.             put " It was" && it & "%" && relation &&\
  1041.               "than the previous test." after prompt
  1042.         end    if
  1043.     end    if
  1044.     request prompt
  1045.     set s_lastTestTime to thisTestTime
  1046.     unlinkDLL "mmSystem" -- decrement refCount
  1047. end    showElapsedTime
  1048. }
  1049.  
  1050. SCRIPT    "Initialize a conversation with Excel"
  1051. BEHAVIOR    "This function will run Excel if it is not running already.  If a filename is passed to this function it will tell Excel to load that file if it is not loaded already. "
  1052. CATEGORY    Windows
  1053. {
  1054. to get InitializeExcel fileNameToRun
  1055.     
  1056.     -- Get the current status of Excel
  1057.     getRemote "Status" application "Excel" topic "System"
  1058.     
  1059.     -- If it failed because there is no server
  1060.     -- run excel
  1061.     if item 1 of sysError = "Failed: No Server"
  1062.         linkDLL sysToolBookDirectory & "tb40win.dll"
  1063.             INT yieldApp()
  1064.         end linkDLL 
  1065.         run "excel.exe" && fileNameToRun
  1066.         -- give excel a break
  1067.         get yieldApp()
  1068.         getRemote "Status" application "Excel" topic "System"
  1069.         unlinkDLL sysToolBookDirectory & "tb40win.dll"
  1070.       end    if
  1071.       
  1072.       -- getRemote status should return Ready
  1073.     if it <> "Ready" 
  1074.         return FALSE
  1075.     end if
  1076.    
  1077.        -- Make sure that it is not minimized
  1078.     executeRemote "[App.Restore()]" application "excel"
  1079.     
  1080.     -- If no file has been specified then return successfully
  1081.     if fileNameToRun = NULL 
  1082.         return TRUE
  1083.     end if
  1084.     
  1085.     -- Check to see if fFileName is open and, if so, 
  1086.     -- make it active
  1087.     executeRemote "[Activate(""" & fileNameToRun & """)]" \
  1088.      application "excel" topic fileNameToRun
  1089.     
  1090.     -- If it failed because there is no server then try 
  1091.     -- opening the file
  1092.     if item 1 of sysError = "Failed: No Server" 
  1093.         executeRemote "[Open(""" & fileNameToRun & """)]" \
  1094.          application "excel"
  1095.     end if
  1096.     
  1097.     -- If sysError is OK then success
  1098.     if item 1 of sysError = "OK" 
  1099.         return TRUE
  1100.     end if
  1101.     return FALSE
  1102. end    InitializeExcel
  1103. }
  1104.  
  1105. SCRIPT    "Bring a ToolBook window to the front"
  1106. BEHAVIOR    "Dynamically brings a ToolBook window to the front. Useful when running different ToolBook applications from a central book. "
  1107. CATEGORY    Windows
  1108. {
  1109. to handle bringWindowToFront appNameToRun
  1110.     
  1111.     linkDLL "user"  
  1112.         --bringWindowToTop is a Windows function that
  1113.         --puts the Window whose window handle is passed to it
  1114.         --in front of all the other windows.
  1115.         INT bringWindowToTop(WORD)
  1116.     end linkDLL
  1117.     
  1118.     --getRemote returns 9 separate items in sysError  
  1119.     --item 1 is the status of the remote request
  1120.        getRemote "sysWindowHandle" application  toolBook topic appNameToRun
  1121.     if (item 1 of sysError) is "OK"
  1122.         get bringWindowToTop(it)
  1123.         --bringWindowToTop doesn't size to page or even 
  1124.         --restore it
  1125.         executeRemote "send SizeToPage" application toolbook \
  1126.          topic appNameToRun
  1127.     else
  1128.         --the app isn't running, so we'll start it
  1129.         run appNameToRun
  1130.     end if
  1131.     
  1132.     unlinkDLL "user"
  1133. end bringWindowToFront
  1134. }
  1135.  
  1136. SCRIPT    "Get the screen resolution"
  1137. BEHAVIOR    "Sets the variable screenResolution to the screen resolution. "
  1138. CATEGORY    Windows
  1139. {
  1140. to get screenRes
  1141.     local hRes, vRes, screenResolution
  1142.  
  1143.     linkDLL sysToolBookDirectory & "tb40win.dll"
  1144.         INT horizontalDisplayRes()
  1145.         INT verticalDisplayRes()
  1146.     end    linkDLL
  1147.     set hRes to horizontalDisplayRes()
  1148.     set vRes to verticalDisplayRes()
  1149.  
  1150.     push vRes onto screenResolution  -- item 2 is verticle resolution
  1151.     push hRes onto screenResolution  -- item 1 is horizontal resolution
  1152.  
  1153.     unlinkDLL sysToolBookDirectory & "tb40win.dll"
  1154.     return screenResolution
  1155. end screenRes
  1156. }
  1157.  
  1158. SCRIPT    "Get the resolution of the printer"
  1159. BEHAVIOR    "Returns the dot per inch that the printer prints "
  1160. CATEGORY    Windows
  1161. {
  1162. to get printerRes
  1163.     linkDll "GDI"
  1164.         WORD     createIC    (STRING,STRING,STRING,STRING)
  1165.         INT    getDeviceCaps    (WORD,INT)
  1166.         INT     deleteDC     (WORD)
  1167.     end linkDLL
  1168.     
  1169.     linkDLL sysToolBookDirectory & "tb40win.dll"
  1170.         STRING GetWinIniVar     (STRING, STRING)
  1171.     end linkDLL
  1172.     
  1173.     LOGPIXELSX = 88 -- Windows constants
  1174.     LOGPIXELSY = 90 
  1175.     
  1176.     driverInfo = getWinIniVar("windows", "device")
  1177.     deviceName = item 1 of driverInfo
  1178.     
  1179.     if deviceName is NULL
  1180.         set sysError to "There is no printer attached."
  1181.         unlinkDLL "GDI"
  1182.         unlinkDLL sysToolBookDirectory & "tb40win.dll"
  1183.         return NULL
  1184.     end if
  1185.     
  1186.     deviceFile = item 2 of driverInfo
  1187.     devicePort = item 3 of driverInfo
  1188.     
  1189.     hDC = createIC(deviceFile,deviceName,devicePort,NULL)
  1190.     prnXRes = getDeviceCaps(hDC,LOGPIXELSX)
  1191.     prnYRes = getDeviceCaps(hDC,LOGPIXELSY)
  1192.     get deleteDC(hDC)
  1193.     
  1194.     unlinkDLL "GDI"
  1195.     unlinkDLL sysToolBookDirectory & "tb40win.dll"
  1196.     return prnXRes & "," & prnYRes
  1197. end printerRes
  1198. }
  1199.  
  1200. SCRIPT    "Get the display resolution"
  1201. BEHAVIOR    "Gets the pixels per inch for the display monitor "
  1202. CATEGORY    Windows
  1203. {
  1204. to get displayRes
  1205.     
  1206.     linkDLL sysToolBookDirectory & "tb40win.dll"
  1207.         INT    displayLogPixelsX()
  1208.         INT displayLogPixelsY()
  1209.     end linkDLL
  1210.     
  1211.     displayPixX = displayLogPixelsX()
  1212.     displayPixY = displayLogPixelsY()    
  1213.  
  1214.     unlinkDLL sysToolBookDirectory & "tb40win.dll"
  1215.     return displayPixX & "," & displayPixY
  1216. end displayRes
  1217. }
  1218.  
  1219. SCRIPT    "Get the colors in the display"
  1220. BEHAVIOR    "Returns the number of colors displayed "
  1221. CATEGORY    Windows
  1222. {
  1223. to get numColors
  1224.     linkDLL "gdi"
  1225.         INT getDeviceCaps(WORD,INT)
  1226.     end linkDLL
  1227.  
  1228.     linkDLL "user"
  1229.         WORD getDC(WORD)
  1230.         INT  releaseDC(WORD,WORD)
  1231.     end linkDLL
  1232.     
  1233.     hDC = getDC(windowHandle of mainWindow)
  1234.     retVal = getDeviceCaps(hDC,24) -- 24 is the magic number for colors
  1235.     get ReleaseDC(windowHandle of mainWindow, hDC)
  1236.     unlinkDLL "gdi"
  1237.     unlinkDLL "user"
  1238.     return retVal
  1239. end    numColors
  1240. }
  1241.  
  1242. SCRIPT    "Get the color of a pixel"
  1243. BEHAVIOR    "Get the color of any pixel on the screen. "
  1244. CATEGORY    Windows
  1245. {
  1246. to handle buttonClick loc
  1247.     linkDLL "user"
  1248.         WORD getDC(WORD)
  1249.         INT releaseDC(WORD,WORD)
  1250.     end    linkDLL
  1251.     
  1252.     linkDLL "gdi"
  1253.         DWORD getPixel(WORD,INT,INT)
  1254.     end    linkDLL
  1255.     
  1256.     linkDLL sysToolBookDirectory & "tb40WIN.DLL"
  1257.         STRING RGBtoHLS(DOUBLE,DOUBLE,DOUBLE)
  1258.      end    linkDLL
  1259.     
  1260.     get pageUnitsToClient(loc)
  1261.     set xCoord to item 1 of it
  1262.     set yCoord to item 2 of it
  1263.     set hDC to getDC(sysClientHandle)
  1264.     get getPixel(hDC, xCoord, yCoord)
  1265.     if it <> -1     -- unlikely
  1266.         redValue = it mod 256 -- get the lobyte of the loword
  1267.         it = it bitShiftRight 8
  1268.         greenValue = it mod 256 -- get the lobyte of the loword
  1269.         blueValue = it bitShiftRight 8
  1270.         
  1271.         set HLSValue to RGBtoHLS(redValue, greenValue, blueValue)
  1272.         if HLSValue = -20     -- very unlikely
  1273.             request "RGB to HLS conversion failed "
  1274.             unlinkDLL "gdi"
  1275.             unlinkDLL "user"
  1276.             unlinkDLL sysToolBookDirectory & "tb40win.dll"
  1277.             break buttonUp
  1278.         end    if
  1279.         
  1280. --        set text of field "RGB" to redValue&","&greenValue&","&blueValue
  1281. --        set text of field "HLS" to HLSValue
  1282. --        set fillColor of rectangle "color" to HLSValue
  1283.         request "RGB is" && redValue&","&greenValue&","&blueValue
  1284.         request "HLS is" && HLSValue
  1285.     else 
  1286.         request "Error getting pixel."
  1287.     end    if
  1288.     get ReleaseDC(sysWindowHandle, hDC)
  1289.     unlinkDLL "gdi"
  1290.     unlinkDLL "user"
  1291.     unlinkDLL sysToolBookDirectory & "tb40win.dll"
  1292. end buttonClick
  1293. }
  1294.  
  1295. SCRIPT    "Get the running version of Windows"
  1296. BEHAVIOR    "Returns the running version of Windows. "
  1297. CATEGORY    Windows
  1298. {
  1299. to get winVersion
  1300.     linkDLL "kernel"
  1301.         DWORD GetVersion()
  1302.     end
  1303.     set verNum to GetVersion()
  1304.     set WverNum to verNum mod 65536
  1305.     set majorNumber to WverNum mod 256
  1306.     set minorNumber to WverNum div 256
  1307.     unlinkDLL "kernel"
  1308.     return majorNumber &"." & minorNumber
  1309.  end winVersion    
  1310. }
  1311.  
  1312. SCRIPT    "Get the current version of DOS"
  1313. BEHAVIOR    "Returns the running versions of DOS "
  1314. CATEGORY    DOS
  1315. {
  1316. to get DOSVersion
  1317.     linkDLL "kernel"
  1318.         DWORD GetVersion()
  1319.     end
  1320.     set verNum to GetVersion()
  1321.     set DverNum to verNum div 65536
  1322.      set dmajorNumber to DverNum div 256
  1323.     set dminorNumber to DverNum mod 256
  1324.     unlinkDLL "kernel"
  1325.     return dmajorNumber & "." & dminorNumber
  1326. end DOSVersion
  1327. }
  1328.  
  1329. SCRIPT    "Exit and restart Windows"
  1330. BEHAVIOR    "This handler demonstrates a way to leave and restart Windows. "
  1331. CATEGORY    Windows
  1332. {
  1333. --When restart is true, Windows will exit and restart.  
  1334. --If if restart is null or false, Windows will just exit.
  1335. to handle exitWindows restart
  1336.     linkDLL "user"
  1337.         INT ExitWindows (DWORD, INT)
  1338.     end linkDLL
  1339.     if restart is true
  1340.         get ExitWindows (66, 0)
  1341.     else
  1342.         get ExitWindows (0, 0)
  1343.     end if
  1344.     -- no need to unlink this one.
  1345. end    exitWindows
  1346. }
  1347.  
  1348. ACTION    "Get custom sys info"
  1349. BEHAVIOR    "Returns information on the system multimedia drivers "
  1350. CATEGORY    Multimedia
  1351. ARG    mediaType    ONEOF    "all,animation,bitmap,cdAudio,digitalVideo,overlay,sequencer,vcr,videodisc,waveAudio"    IS    "all"    help    "Choose a device type."
  1352. ARG    info    ONEOF    "installname, quantity, quantity open, name 1, name 1 open"    IS    "installname"    help    "Get this information about the device."
  1353. {
  1354.       sMS = sysMediaSuspend
  1355.     sysMediaSuspend = FALSE
  1356.     clear sysError
  1357.     devType = "$$mediaType"
  1358.     info = "$$info"
  1359.  
  1360.     get callMCI("sysInfo" && devType && info)
  1361.     if sysError is NULL
  1362.         request it 
  1363.     else
  1364.         if sMS = TRUE -- we'll trap the error if the user is expecting it
  1365.             request "Device" && QUOTE & devType & QUOTE && "does not understand" \
  1366.                 && QUOTE & info & QUOTE & ":" & CRLF & CRLF & sysError
  1367.         end if
  1368.     end if
  1369.     sysMediaSuspend = sMS
  1370. }
  1371.  
  1372. ACTION    "Get device capabilities"
  1373. BEHAVIOR    "Returns information on the capabilities of the multimedia drivers "
  1374. CATEGORY    Multimedia
  1375. ARG    mediaType    ONEOF    "all,animation,bitmap,cdAudio,digitalVideo,overlay,sequencer,vcr,videodisc,waveAudio"    IS    "all"    help    "Choose a device type."
  1376. ARG    info    ONEOF    "can eject,can freeze,can play,can record,can reverse,can save,can stretch,compound device,device type,fast play rate,has audio,has video,inputs,normal play rate,outputs,slow play rate,uses files,uses palettes,windows"    IS    "device type"    help    "Get this information about the device."
  1377. {
  1378.     -- If the behavior is not supported by the driver, but is supported
  1379.     -- in the spec, this function will return FALSE. If the behavior is
  1380.     -- not supported in the spec, this will return NULL and set up
  1381.     -- a report that is shown if sysMediaSuspend is TRUE
  1382.     sMS = sysMediaSuspend
  1383.     sysMediaSuspend = FALSE
  1384.     clear sysError
  1385.     devType = "$$mediaType"
  1386.     cap = "$$info"
  1387.     get callMCI("capability" && devType && cap)
  1388.     if sysError is NULL
  1389.         request it 
  1390.     else
  1391.         if sMS = TRUE -- we'll trap the error if the user is expecting it
  1392.             request "Device" && QUOTE & devType & QUOTE && "does not understand" \
  1393.                 && QUOTE & cap & QUOTE & ":" & CRLF & CRLF & sysError
  1394.         end if
  1395.     end if
  1396.     sysMediaSuspend = sMS    
  1397. }
  1398.  
  1399. ACTION    "Set mixer values"
  1400. BEHAVIOR    "Sets the volume for the virtual audio mixer "
  1401. CATEGORY    Multimedia
  1402. ARG    lineType    ONEOF    "device_in,device_out"    IS    "device_in"    help    "Choose input or output"
  1403. ARG    lineSpec    ONEOF    "AMP,AUX,CDA,MIC,MUS,WAV"    IS    "WAV"    help    "Choose the MCI device to query"
  1404. ARG    channel    ONEOF    "LEFT,RIGHT,BOTH"    IS    "BOTH"    help    "Choose which channel"
  1405. ARG    value    ONEOF    "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100"    IS    "99"    help    "Choose the percent of full volume"
  1406. {
  1407.     -- The virtual mixer does the best it can with whatever 
  1408.     -- soundcard is on the target machine. As there is no real 
  1409.     -- standard, results will vary from card to card.
  1410.     clear sysError
  1411.     get mixerCommand("set tbkmixer $$lineType $$lineSpec control volume $$channel value")
  1412.     if it = 0
  1413.         if $$channel <> "both"
  1414.             request "Volume for the $$channel channel of the $$lineSpec device has been set to $$value"
  1415.         else
  1416.             request "Volume for both channels of the $$lineSpec device have been set to $$value"
  1417.         end if
  1418.     else
  1419.         request sysError
  1420.     end if
  1421. }
  1422.  
  1423. ACTION    "Let user set mixer values for a device"
  1424. BEHAVIOR    "Lets the user set the volume for the virtual audio mixer "
  1425. CATEGORY    Multimedia
  1426. ARG    lineType    ONEOF    "device_in,device_out"    IS    "device_in"    help    "Choose input or output"
  1427. ARG    lineSpec    ONEOF    "AMP,AUX,CDA,MIC,MUS,WAV"    IS    "WAV"    help    "Choose the MCI device to query"
  1428. {
  1429.     -- The virtual mixer does the best it can with whatever 
  1430.     -- soundcard is on the target machine. As there is no real 
  1431.     -- standard, results will vary from card to card.
  1432.     -- This script lets the author decide which device, 
  1433.     -- but lets the user decide what value
  1434.     local l_cancel,l_channel,l_value
  1435.     request "What channel would you like to set the volume of: the left, right, or both channels?" \
  1436.         with "Left" or "Right" or "Both"
  1437.     if it <> null -- null when canceled with the system button or alt-F4
  1438.         set l_channel to it
  1439.     else
  1440.         set l_cancel to TRUE,"the user canceled."
  1441.     end if
  1442.     
  1443.     if item 1 of l_cancel <> TRUE
  1444.         ask "What percent of full volume should the setting be?" with "50"
  1445.         if isType(INT,it) and it >= 0  and it <=100
  1446.             set l_value to it
  1447.         else
  1448.             set l_cancel to TRUE,"there was a bad value for volume."
  1449.         end if
  1450.     end if
  1451.     clear sysError
  1452.     if item 1 of l_cancel <> TRUE
  1453.         get mixerCommand("set tbkmixer $$lineType $$lineSpec control volume" && l_channel && l_value)
  1454.         if it = 0
  1455.             if l_channel <> "both"
  1456.                 request "Volume for the" && l_channel && "channel of the $$lineSpec device has been set to" && l_value
  1457.             else
  1458.                 request "Volume for both channels of the $$lineSpec device have been set to" && l_value
  1459.             end if
  1460.         else
  1461.             request sysError
  1462.         end if
  1463.     else
  1464.         request "The command was not executed because" && item 2 of l_cancel
  1465.     end if
  1466. }
  1467.  
  1468. ACTION    "Get mixer values"
  1469. BEHAVIOR    "Gets the volume for the virtual audio mixer "
  1470. CATEGORY    Multimedia
  1471. ARG    lineType    ONEOF    "device_in,device_out"    IS    "device_in"    help    "Choose input or output"
  1472. ARG    lineSpec    ONEOF    "AMP,AUX,CDA,MIC,MUS,WAV"    IS    "WAV"    help    "Choose the MCI device to query"
  1473. ARG    channel    ONEOF    "LEFT,RIGHT,BOTH"    IS    "BOTH"    help    "Choose which channel"
  1474. {
  1475.     -- The virtual mixer does the best it can with whatever 
  1476.     -- soundcard is on the target machine. As there is no real 
  1477.     -- standard, results will vary from card to card.
  1478.     clear sysError
  1479.     get mixerCommand("get tbkmixer $$lineType $$lineSpec control volume $$channel")
  1480.     if sysError is NULL
  1481.         if $$channel <> "both"
  1482.             request "Volume for the $$channel channel of the $$lineSpec device is set to" && it
  1483.         else
  1484.             request "Volume for both channels of the $$lineSpec device are set to" && it
  1485.         end if
  1486.     else
  1487.         request sysError
  1488.     end if
  1489. }
  1490.  
  1491. ACTION    "Image Command - Capability"
  1492. BEHAVIOR    "Requests information about the capability of the bitmap player "
  1493. CATEGORY    Images
  1494. ARG    args    ONEOF    "compound device,device type,has files,has video,static,uses palettes"    IS    "device type"    help    "Choose what capability."
  1495. {
  1496.     get imageCommand("capability placeHolder $$args")
  1497.     request it
  1498. }
  1499.  
  1500. ACTION    "Image Command - Close"
  1501. BEHAVIOR    "Closes the window and file associated with the alias "
  1502. CATEGORY    Images
  1503. ARG    alias    IS    "myAlias"    help    "The filename or the alias you want to close or ALL to close all open bitmaps. Keep your aliases consistent!"
  1504. {
  1505.     get imageCommand("close $$alias")
  1506. }
  1507.  
  1508. ACTION    "Image Command - Info"
  1509. BEHAVIOR    "Get info on the window or file associated with the alias "
  1510. CATEGORY    Images
  1511. ARG    alias    IS    "myAlias"    help    "The filename or the alias you want information on. Keep your aliases consistent!"
  1512. ARG    args    ONEOF    "product,text,file"    IS    "file"    help    "The type of information you want."
  1513. {
  1514.     get imageCommand("info $$alias $$args")
  1515.     request it
  1516. }
  1517.  
  1518. ACTION    "Image Command - Open"
  1519. BEHAVIOR    "Initializes the displayer and associates the file with the alias "
  1520. CATEGORY    Images
  1521. ARG    myBitmap    FILE    "Bitmap Files(*.BMP),*.bmp,(*.DIB),*.dib"    IS    "Cars.bmp"    help    "Find the bitmap file to display."
  1522. ARG    alias    IS    "myAlias"    help    "The alias you want associated with this file. Keep your aliases consistent!"
  1523. ARG    style    ONEOF    "overlapped,popup,child"    IS    "overlapped"    help    "Choose the style of the window."
  1524. {
  1525.     get imageCommand("open $$myBitmap alias $$alias style $$style")
  1526. }
  1527.  
  1528. ACTION    "Image Command - Play"
  1529. BEHAVIOR    "Play the file in the window associated with the alias "
  1530. CATEGORY    Images
  1531. ARG    alias    IS    "myAlias"    help    "The filename or the alias you want to play. Keep your aliases consistent!"
  1532. {
  1533.     get imageCommand("play $$alias")
  1534. }
  1535.  
  1536. ACTION    "Image Command - Put"
  1537. BEHAVIOR    "Play the file in the window associated with the alias "
  1538. CATEGORY    Images
  1539. ARG    alias    IS    "myAlias"    help    "The filename or the alias you want to play. Keep your aliases consistent!"
  1540. ARG    whereTo    ONEOF    "source,destination"    IS    "destination"    help    "Get the offset and extent of the source or destination."
  1541. ARG    x1    IS    "0"    help    "Left to right offset."
  1542. ARG    y1    IS    "0"    help    "Up to down offset."
  1543. ARG    x2    IS    "100"    help    "Left to right extent."
  1544. ARG    y2    IS    "100"    help    "Up to down extent."
  1545. {
  1546.     get imageCommand("put $$alias $$whereTo at $$x1 $$y1 $$x2 $$y2")
  1547. }
  1548.  
  1549. ACTION    "Image Command - Status"
  1550. BEHAVIOR    "Get the status of the window and file associated with the alias "
  1551. CATEGORY    Images
  1552. ARG    alias    IS    "myAlias"    help    "The filename or the alias you want the status of. Keep your aliases consistent!"
  1553. ARG    args    ONEOF    "window,position,extent,size,visible,style,palette"    IS    "position"    help    "The element you need the status of."
  1554. {
  1555.     get imageCommand("status $$alias $$args")
  1556.     request it
  1557. }
  1558.  
  1559. ACTION    "Image Command - Where"
  1560. BEHAVIOR    "Obtains the rectangle specifying the source or destination area of the image. "
  1561. CATEGORY    Images
  1562. ARG    whereTo    ONEOF    "source,destination"    IS    "destination"    help    "Get the offset and extent of the source or destination."
  1563. ARG    alias    IS    "myAlias"    help    "The filename or the alias you want. Keep your aliases consistent!"
  1564. {
  1565.     get imageCommand("where $$alias $$whereto")
  1566.     request it
  1567. }
  1568.  
  1569. ACTION    "Image Command - Window"
  1570. BEHAVIOR    "Change parameters of the window associated with the alias "
  1571. CATEGORY    Images
  1572. ARG    alias    IS    "myAlias"    help    "The filename or the alias you want to close or ALL to close all open bitmaps. Keep your aliases consistent!"
  1573. ARG    args    ONEOF    "text,position,size"    IS    "position"    help    "Choose what aspect of the window to change."
  1574. ARG    value    IS    "myValue"    help    "For 'text' the caption of the window or use 'default' for the name of the bitmap. For 'position'and 'size' use two pixels e.g. '100"
  1575. {
  1576.     get imageCommand("window $$alias $$args $$value")
  1577. }
  1578.  
  1579. ACTION    "Image Command - Window State"
  1580. BEHAVIOR    "Change the state of the window associated with the alias "
  1581. CATEGORY    Images
  1582. ARG    alias    IS    "myAlias"    help    "The filename or the alias you want to close or ALL to close all open bitmaps. Keep your aliases consistent!"
  1583. ARG    value    ONEOF    "hide,minimize,minimized,show,maximize,iconic,asIs,asWas,normal"    IS    "show"    help    "Use one of these constants to more precisely control the way the window is displayed."
  1584. {
  1585.     get imageCommand("window $$alias state $$value")
  1586. }
  1587.  
  1588. ACTION    "Play a Wave file as a new clip"
  1589. BEHAVIOR    "Creates a clip from a wave file using 'WaveFile' ($$WaveFile,) then plays it. "
  1590. CATEGORIES    Clips,Audio
  1591. ARG    waveFile    FILE    "Wave Files(*.WAV),*.wav"    IS    "Chord.Wav"    help    "Get the wave file."
  1592. ARG    clipName    IS    "myClip"    help    "Give the new clip a name."
  1593. ARG    startTime    IS    "0:00:00"    help    "Set to a time in 'Minutes:Seconds:Milliseconds' format; defaults to beginning of the file."
  1594. ARG    endTime    IS    "0:10:00"    help    "Set to a time in 'Minutes:Seconds:Milliseconds' format; defaults to 10 seconds into the file."
  1595. {
  1596.      -- The new clip is made when this script is activated, 
  1597.      -- not when it is written, so make sure the media is 
  1598.      -- still in the right place before activating this script
  1599.       new clip from "$$WaveFile"
  1600.       name of it = "$$clipName"
  1601.       mediaRef = clip "$$clipName"
  1602.       mmTimeFormat of mediaRef = "MSms"
  1603.       mmBeginPoint of mediaRef = "$$startTime"
  1604.       mmEndPoint of mediaRef = "$$endTime"
  1605.       mmPlay mediaRef autoclose
  1606. }
  1607.  
  1608. ACTION    "Play an AVI file as a clip"
  1609. BEHAVIOR    "Creates a clip from an AVI file using 'AVIFile' ($$AVIFile,) then plays it. "
  1610. CATEGORIES    Clips,Video
  1611. ARG    AVIFile    FILE    "AVI Files(*.avi),*.avi"    IS    "windmill.avi"    help    "Get the wave file."
  1612. ARG    clipName    IS    "myClip"    help    "Give the new clip a name."
  1613. ARG    startTime    IS    "0"    help    "Set to frame number; defaults to beginning of the file."
  1614. ARG    endTime    IS    "300"    help    "Set to a frame number; defaults to frame 300."
  1615. ARG    StageObj    OBJTYP    "Stage"    IS    "stage myStage"    help    "Choose the stage object for playback"
  1616. {
  1617.      -- The new clip is made when this script is activated, 
  1618.      -- not when it is written, so make sure the media is 
  1619.      -- still in the right place before activating this script
  1620.       new clip from "$$AVIFile"
  1621.       name of it = "$$clipName"
  1622.       mediaRef = clip "$$clipName"
  1623.       mmTimeFormat of mediaRef = "frames"
  1624.       mmBeginPoint of mediaRef = "$$startTime"
  1625.       mmEndPoint of mediaRef = "$$endTime"
  1626.       mmPlay mediaRef in $$StageObj autoclose
  1627. }
  1628.  
  1629. ACTION    "Build and play an AVI clip w/out the clip manager"
  1630. BEHAVIOR "Allows the user to create a clip from an AVI file then plays it."
  1631. CATEGORY    Clips,Video
  1632. ARG ClipName is "Enter a name for the new clip" help "This is the default text the user will see or modify for your needs."
  1633. ARG StageObj OBJTYP "Stage" is "stage myStage" help "Choose the stage object for playback"
  1634. ARG BeginPoint is "Enter a beginning point for the clip in frames" help "This is the default text the user will see or modify for your needs."
  1635. ARG EndPoint is "Enter an ending point for the clip in frames" help "This is the default text the user will see or modify for your needs."
  1636. ARG    caption    is    "Open an AVI File"    help "This is the default text the user will see or modify for your needs."
  1637. ARG    prompt    is    "Choose the AVI file to open" help "This is the default text the user will see or modify for your needs."
  1638. {
  1639.      -- The new clip is made by the user, so this is more
  1640.      -- flexible than the 'Play a Wave file as a clip' script.
  1641.      -- This is a good sample script, as defauults and errorrs 
  1642.      -- are handled fairly gracefully.
  1643.     while not (sysSupportedMedia contains "digitalVideo")
  1644.         request  "Error: breaking execution of this script." & CRLF \
  1645.           & "Multimedia ToolBook is not being allowed to play digitalVideo." & CRLF \
  1646.           & "The appropriate drivers may not be available."
  1647.         break to system
  1648.     end while
  1649.     linkDll sysToolBookDirectory & "tb40dlg.dll"
  1650.         string openDlg(string,string,string,string)
  1651.     end    linkDLL
  1652.     
  1653.     get openDlg(".","*.avi","$$prompt","$$caption")
  1654.     if it <> null    
  1655.         newAVI = it
  1656.         
  1657.         do
  1658.             ask "$$ClipName" with "newClip"
  1659.             if it is null
  1660.                 request "Are you sure you want to cancel creating this clip?" \
  1661.                   with "Yes, cancel" or "No, try again"
  1662.                 if it contains "Yes"
  1663.                     break to system
  1664.                 else
  1665.                     clear it
  1666.                   end if
  1667.             end if
  1668.         until it <> null
  1669.         clipName = it
  1670.         
  1671.         new clip from newAVI
  1672.         name of it = clipName
  1673.         mediaRef = clip clipName
  1674.         while not (mmPlayable of mediaRef)
  1675.             request "This clip is not playable"
  1676.             break to system
  1677.         end while
  1678.         mmTimeFormat of mediaRef = "frames"
  1679.         
  1680.          sS = sysSuspend
  1681.         sMS = sysMediaSuspend
  1682.         sysSuspend = FALSE
  1683.         sysMediaSuspend = FALSE
  1684.                 
  1685.         ask  "$$BeginPoint" with "0"
  1686.         clear sysError
  1687.         mmBeginPoint of mediaRef = it
  1688.         if sysError <> null
  1689.             request "Error, the beginning point of the clip set to default: ""0"""
  1690.             mmBeginPoint of mediaRef = "0"
  1691.         end if
  1692.         
  1693.         ask "$$EndPoint" with "300"
  1694.         clear sysError
  1695.          mmEndPoint of mediaRef = it
  1696.         if sysError <> null
  1697.             request "Error, the ending point of the clip set to default: ""300"""
  1698.             mmEndPoint of mediaRef = "300"
  1699.         end if
  1700.         
  1701.         sysSuspend = sS
  1702.         sysMediaSuspend = sMS
  1703.         if mmPlayable of mediaRef
  1704.             mmPlay mediaRef in $$StageObj autoclose 
  1705.         end if
  1706.     end if
  1707.     
  1708.     unlinkDLL sysToolBookDirectory & "tb40dlg.dll"
  1709. }
  1710.  
  1711. ACTION    "Build and play a Wave clip"
  1712. BEHAVIOR "Allows the user to create a clip from a wave file then plays it."
  1713. CATEGORY    Clips,Audio
  1714. ARG ClipName is "Enter a name for the new clip" help "Default is good or modify for your needs."
  1715. ARG BeginPoint is "Enter a beginning point for the clip in 'Minutes:Seconds:Milliseconds'" help "Default is good or modify for your needs."
  1716. ARG EndPoint is "Enter an ending point for the clip in 'Minutes:Seconds:Milliseconds'" help "Default is good or modify for your needs."
  1717. ARG    caption    is    "Open a Wave File"    help "Default is good or modify for your needs."
  1718. ARG    prompt    is    "Choose the wave file to open" help "Default is good or modify for your needs."
  1719. {
  1720.      -- The new clip is made by the user, so this is more
  1721.      -- flexible than the 'Play a Wave file as a clip' script.
  1722.      -- This is a good sample script, as defauults and errorrs 
  1723.      -- are handled fairly gracefully.
  1724.  
  1725.     -- this funny structure gets around auto-script choking when it sees the break
  1726.     -- statement in an "if" structure
  1727.     while not (sysSupportedMedia contains "waveAudio")
  1728.         request  "Error: breaking execution of this script." & CRLF \
  1729.           & "The multimedia driver can not find the waveAudio device." & CRLF \
  1730.           & "The appropriate drivers may not be available."
  1731.         break to system
  1732.     end while
  1733.     linkDll sysToolBookDirectory & "tb40dlg.dll"
  1734.         string openDlg(string,string,string,string)
  1735.     end    linkDLL
  1736.     
  1737.     get openDlg(".","*.wav","$$prompt","$$caption")
  1738.     if it <> null    
  1739.         newWave = it
  1740.         
  1741.         do
  1742.             ask "$$ClipName" with "newClip"
  1743.             if it is null
  1744.                 request "Are you sure you want to cancel creating this clip?" \
  1745.                   with "Yes, cancel" or "No, try again"
  1746.                 if it contains "Yes"
  1747.                     break to system
  1748.                 else
  1749.                     clear it
  1750.                   end if
  1751.             end if
  1752.         until it <> null
  1753.         clipName = it
  1754.         
  1755.         new clip from newWave
  1756.         name of it = clipName
  1757.         mediaRef = clip clipName
  1758.         mmTimeFormat of mediaRef = "MSms"
  1759.         
  1760.          sS = sysSuspend
  1761.         sMS = sysMediaSuspend
  1762.         sysSuspend = FALSE
  1763.         sysMediaSuspend = FALSE    
  1764.         
  1765.         ask  "$$BeginPoint" with "0:00:00"
  1766.         clear sysError
  1767.         mmBeginPoint of mediaRef = it
  1768.         if sysError <> null
  1769.             request "Error, the beginning point of the clip set to default: ""0:00:00"""
  1770.             mmBeginPoint of mediaRef = "0:00:00"
  1771.         end if
  1772.         
  1773.         ask "$$EndPoint" with "0:05:00"
  1774.         clear sysError
  1775.          mmEndPoint of mediaRef = it
  1776.         if sysError <> null
  1777.             request "Error, the ending point of the clip set to default: ""0:05:00"""
  1778.             mmEndPoint of mediaRef = "0:05:00"
  1779.         end if
  1780.         
  1781.         sysSuspend = sS
  1782.         sysMediaSuspend = sMS
  1783.         if mmPlayable of mediaRef
  1784.             mmPlay mediaRef autoclose
  1785.         end if
  1786.     end if
  1787.     
  1788.     unlinkDLL sysToolBookDirectory & "tb40dlg.dll"
  1789. }
  1790.  
  1791. ACTION    "Set book to read automatically"
  1792. BEHAVIOR    "Example program for a continuously running book. "
  1793. CATEGORY    Navigation
  1794. HANDLERS    enterApplication, enterBook, enterBackground, buttonClick, buttonUp, buttonDown
  1795. ARG    Effect    ONEOF    "blinds,dissolve,drip,fade,iris,puzzle,tear"    IS    "fade"
  1796. ARG    Speed    ONEOF    "Normal,Fast,Slow"    IS    "Normal"
  1797. ARG    pauseTime    ONEOF    "1,2,3,4,5,6,7,8,9,10"    IS    "5"    help    "Time in seconds to pause on a page."
  1798. {
  1799.      send reader
  1800.     send sizeToPage
  1801.     set caption of mainWindow to name of this page
  1802.     forward
  1803.      
  1804.     -- defeat imaging behavior
  1805.     set sysLockScreen to TRUE
  1806.     set sysLockScreen to FALSE
  1807.     
  1808.     show statusBar
  1809.     set caption of statusBar to "Press and hold [space] to stop demo"    
  1810.     
  1811.     while keyState(keySpace) <> down
  1812.         transition    "$$effect $$speed" to next page
  1813.         set caption of mainWindow to name of this page
  1814.         pause $$pauseTime
  1815.     end while
  1816.     set caption of statusBar to " "
  1817. }
  1818.  
  1819. ACTION    "Step through a clip"
  1820. BEHAVIOR    "Step through a video or animation "
  1821. CATEGORIES    Clips, Stages, Video
  1822. ARG    ClipRef    CLIP    IS    "clip id 100"    help    "Select the clip to be played."
  1823. ARG    StepSize    IS    "1"    help    "Any integer value from 1 up to the frame count of the clip."
  1824. ARG    StageObj    OBJTYP    "Stage"    IS    "stage myStage"    help    "Choose the stage object for showing"
  1825. ARG    StepDelay    ONEOF    "1000,500,100"    IS    "100"    help    "'50' = 1/2 of a second."
  1826. {
  1827.     if mmIsOpen of $$ClipRef
  1828.         mmClose $$ClipRef wait
  1829.     end if
  1830.     mmOpen $$ClipRef  wait
  1831.  
  1832.     oldMTF = mmTimeFormat of $$ClipRef 
  1833.     mmTimeFormat of $$ClipRef  = "frames"
  1834.     frameVar= $$StepSize
  1835.     
  1836.     maxFrame = mmLength of $$ClipRef 
  1837.     conditions
  1838.     when frameVar < 1
  1839.         frameVar = 1
  1840.     when frameVar > maxFrame
  1841.         frameVar = maxFrame
  1842.     end conditions
  1843.  
  1844.     mmCue $$ClipRef
  1845.  
  1846.     conditions
  1847.     when $$StepDelay < 1
  1848.         myDelay = 1
  1849.     when $$StepDelay > 231
  1850.         myDelay = 231
  1851.     else
  1852.         myDelay = $$StepDelay
  1853.     end conditions
  1854.     step i from 1 to (floor(maxframe/frameVar))-1
  1855.         mmShow $$ClipRef  in $$StageObj  wait
  1856.         pause myDelay
  1857.         mmStep $$ClipRef by frameVar
  1858.     end step
  1859.     mmShow clip "windmill"  in $$StageObj  wait
  1860.     mmSeek clip "windMill" to maxFrame
  1861.     mmShow clip "windmill"  in $$StageObj  wait
  1862.     mmTimeFormat of $$ClipRef  = oldMTF
  1863. }
  1864.  
  1865. SCRIPT    "Continuously play a visual clip"
  1866. BEHAVIOR    "Use the mmNotify message to play an animation or video clip continuously. This script would go in the page object. "
  1867. CATEGORIES    Clips,Video
  1868. ARG    ClipRef    CLIP    IS    "clip id 100"    help    "Select the clip to be played."
  1869. ARG    StageObj    OBJTYP    "Stage"    IS    "stage myStage"    help    "Choose the stage object for playback"
  1870. {
  1871. to handle enterPage
  1872.     forward
  1873.     --cue and play the clip at enterPage
  1874.     mmOpen $$ClipRef
  1875.     send playScore
  1876. end enterPage
  1877.  
  1878. to handle playScore
  1879.     mmPlay $$ClipRef in $$StageObj notify self
  1880. end playScore
  1881.  
  1882. to handle mmNotify mediaRef, commandName, cResult
  1883.     if (mediaRef = $$ClipRef) and (cResult = "successful")
  1884.         send playScore
  1885.     end if
  1886. end mmNotify
  1887. }
  1888.  
  1889. SCRIPT    "Continuously play any clip"
  1890. BEHAVIOR    "Use the mmNotify message to play any clip continuously. This script would go in the page object. "
  1891. CATEGORY    Clips
  1892. ARG    ClipRef    CLIP    IS    "clip id 100"    help    "Select the clip to be played."
  1893. {
  1894. to handle enterPage
  1895.     forward
  1896.     --cue and play the clip at enterPage
  1897.     mmOpen $$ClipRef
  1898.     send playScore
  1899. end enterPage
  1900.  
  1901. to handle playScore
  1902.     mmPlay $$ClipRef notify self
  1903. end playScore
  1904.  
  1905. to handle mmNotify mediaRef, commandName, cResult
  1906.     if (mediaRef = $$ClipRef) and (cResult = "successful")
  1907.         send playScore
  1908.     end if
  1909. end mmNotify
  1910. }
  1911.  
  1912. SCRIPT    "Set text of field to position of clip"
  1913. BEHAVIOR    "Use a field to show the current position of a clip as it is being played "
  1914. CATEGORY    Utilities
  1915. ARG    ClipRef    CLIP    IS    "clip id 100"    help    "Select the clip to be monitored."
  1916. {
  1917. -- this script goes in the field displaying the position
  1918. notifyBefore idle
  1919.     cName = $$ClipRef
  1920.     if (mmIsOpen of cName)
  1921.         oldPos = my text
  1922.         newPos = mmPosition of cName
  1923.         if oldPos <> newPos
  1924.             my text = newPos
  1925.         end if
  1926.     end if
  1927. end idle
  1928. }
  1929.  
  1930. SCRIPT    "Creating and using a Windows timer"
  1931. BEHAVIOR    " "
  1932. CATEGORY    Windows
  1933. {
  1934. -- register a windows timer (10 sec)
  1935. to handle startInfoTimer
  1936.     SYSTEM infoTimerID,infoTimer
  1937.     
  1938.     linkdll "user"
  1939.         INT     setTimer        (WORD,INT,WORD,DWORD)
  1940.         INT     killTimer        (WORD,INT)
  1941.     end
  1942.  
  1943.     infoTimer = 4843
  1944.     infoTimerID = art_SetTimer(syswindowhandle,infoTimer,10000,0)         
  1945.     
  1946.     -- watch for a timer message
  1947.     translateWindowMessage for s_hWNDInfo
  1948.           on 275 send doTimer
  1949.     end                                            
  1950. end
  1951.  
  1952. -------------------------------------
  1953.  
  1954. -- kill the timer
  1955. to handle stopInfoTimer
  1956.     SYSTEM infoTimerID,infoTimer
  1957.  
  1958.     if infoTimerID <> NULL
  1959.         get killTimer(syswindowhandle,infoTimerID)
  1960.         untranslateWindowMessage 275 for syswindowhandle
  1961.         clear infoTimerID
  1962.         clear infoTimer
  1963.     end
  1964. end
  1965.  
  1966.  
  1967.     
  1968.  
  1969. }
  1970.  
  1971.